package com.zeyun.EasyOnlineShareCloud.config.saToken;

import cn.dev33.satoken.stp.StpInterface;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zeyun.EasyOnlineShareCloud.dao.entity.UserDO;
import com.zeyun.EasyOnlineShareCloud.dao.mapper.UserMapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;

/**
 * 自定义权限加载接口实现类
 */
@Slf4j
@AllArgsConstructor
@Component
public class StpInterfaceImpl implements StpInterface {

	private final UserMapper userMapper;

	/**
	 * 返回一个账号所拥有的权限码集合
	 */
	@Override
	public List<String> getPermissionList(Object loginId, String loginType) {
		/* List<String> list = new ArrayList<String>();
		list.add("101");
		list.add("user.add");
		list.add("user.update");
		list.add("user.get");
		list.add("user.delete");
		list.add("art.*"); */
		return Collections.emptyList();
	}

	/**
	 * 返回一个账号所拥有的角色标识集合 (权限与角色可分开校验)
	 */
	@Override
	public List<String> getRoleList(Object loginId, String loginType) {
		/* List<String> list = new ArrayList<String>();
		list.add("admin");
		list.add("super-admin"); */
		UserDO userDO = userMapper.selectOne(new LambdaQueryWrapper<UserDO>().eq(UserDO::getId, loginId));
		log.info("id:{}的角色为{}", loginId, userDO.getRole());
		return List.of(userDO.getRole());
	}


}
